/******************************************************************************
 * Copyright (C), 2014, BeeIoT Tech. Co., Ltd. 
 * FileName:        at_api.c
 * Author:          lvxin 
 * Version :        1.0
 * Date:            2014-10-23 10:23:41
 * Description:     AT指令API定义
 * Function List:   1. at_api_init()    --初始化API列表,将列表提供给at_service
 * History:
 * <author>     <time>                <version >  <desc> 
 * lvxin        2014-10-23 10:23:41   1.0         build this moudle 
 *****************************************************************************/

/******************************************************************************
 *  *INCLUDES
 *  */
#include <stdio.h>
#include "at_service.h"
#include "at_base.h"

/******************************************************************************
 *  *MICROS
 *  */

/******************************************************************************
 *  *CONSTANTS
 *  */

/******************************************************************************
 *  *TYPEDEFS
 *  */

/******************************************************************************
 *  *GLOBAL VARIABLES
 *  */

/******************************************************************************
 *  *EXTERNAL VARIABLES
 *  */

/******************************************************************************
 *  *EXTERNAL FUNCTIONS
 *  */

/******************************************************************************
 *  *LOCAL VARIABLES
 *  */

/******************************************************************************
 *  *PROFILE CALLBACKS(DECLARES)
 *  */
static int CCLK_api (int argc, char *argv[]);
static int SPWM_api (int argc, char *argv[]);
static int ok_api (int argc, char *argv[]);

/******************************************************************************
 *  *FUNCTION DECLARES
 *  */

/******************************************************************************
 *  *LOCAL FUNCTIONS
 *  */

/******************************************************************************
 *  *PUBLIC FUNCTIONS
 *  */


static int CSMINS_check_api (int argc, char *argv[]);
static int CREG_check_api (int argc, char *argv[]);
static int COPS_check_api (int argc, char *argv[]);
static int CSCA_check_api (int argc, char *argv[]);
static int CIPSHUT_api (int argc, char *argv[]);

//AT指令的API列表
static at_api_list_t api_list[]={
    {"+CCLK", CCLK_api},
    {"+SPWM", SPWM_api},
    {"E0", ok_api},
    {"+CSDT", ok_api},
    {"+CREG", ok_api},
    {"+CMGF", ok_api},
    {"+CSMINS", ok_api},
    {"+CSMINS?", CSMINS_check_api},
    {"+CREG?", CREG_check_api},
    {"+CSCS", ok_api},
    {"+CLIP", ok_api},
    {"+CNMI", ok_api},
    {"+CSMP", ok_api},
    {"+CALD", ok_api},
    {"+CALA", ok_api},
    {"+CSCS", ok_api},
    {"+CIPMUX", ok_api},
    {"+CIPHEAD", ok_api},
    {"+CGCLASS", ok_api},
    {"+CGDCONT", ok_api},
    {"+CGATT", ok_api},
    {"+CIPCSGP", ok_api},
    {"+CIPSHUT", CIPSHUT_api},
    {"+COPS?", COPS_check_api},
    {"+CSCA?", CSCA_check_api},
};

/******************************************************************************
 * Function:        at_api_init()
 * Description:     初始化API接口
 * Calls:           at_api_list_register()
 * Called By:       at_service_init()
 * Input:            
 * Return:          void
 * Others:           
 *****************************************************************************/
void at_api_init()
{
    at_api_list_register (api_list, sizeof(api_list)/sizeof(api_list[0]));
}

static int COPS_check_api (int argc, char *argv[])
{
    at_base_putstring("\r\n+COPS: 0,0,\"CHINA MOBILE\"\r\n");
    at_base_putstring("\r\nOK\r\n");
    return 0;
}

static int CSCA_check_api (int argc, char *argv[])
{
    at_base_putstring("\r\n+CSCA: \"+8613800240500\",145\r\n");
    at_base_putstring("\r\nOK\r\n");
    return 0;
}

static int CREG_check_api (int argc, char *argv[])
{
    at_base_putstring("\r\n+CREG: 1,1\r\n");
    at_base_putstring("\r\nOK\r\n");
    return 0;
}

static int CSMINS_check_api (int argc, char *argv[])
{
    at_base_putstring("\r\n+CSMINS: 1,1\r\n");
    at_base_putstring("\r\nOK\r\n");
    return 0;
}

static int CIPSHUT_api (int argc, char *argv[])
{
    at_base_putstring("\r\nSHUT OK\r\n");
    return 0;
}

static int ok_api (int argc, char *argv[])
{
    /*at_base_putstring("\r\nOK\r\n");*/
    at_cmdline_echo_en (0);
    at_base_putstring("\r\nOK\r\n");
    return 0;
}

static int CCLK_api (int argc, char *argv[])
{
    int i;
    at_base_printf ("参数列表：\n");
    for (i = 0; i < argc; i ++)
    {
        at_base_printf ("[%d]%s\n", argc, argv[i]);
    }
    return 0;
}

static int SPWM_api (int argc, char *argv[])
{
    int i;
    at_base_printf ("参数列表：\n");
    for (i = 0; i < argc; i ++)
    {
        at_base_printf ("[%d]%s\n", argc, argv[i]);
    }
    at_base_printf ("%s", "hello");
    return 0;
}

